using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace JTLeigh.Tools.Development.CopySourceAsHtml.UnitTests
{

    /// <summary>
    /// Unit tests for the <see cref="HtmlColor"/> class.
    /// </summary>
    [TestClass]
    public class HtmlColorFixture
    {
        #region Methods

		#region ConvertOleColor

		/// <summary>
		/// Ensures <see cref="HtmlColor.ConvertOleColor"/> correctly throws <see cref="ArgumentException"/>
		/// when called with an invalid OLE color.
		/// </summary>
		[TestMethod]
		[ExpectedException(typeof(ArgumentException))]
		public void TestConvertOleColorWithInvalidOleColor()
		{
			HtmlColor.ConvertOleColor(uint.MaxValue);
		}

		/// <summary>
		/// Ensures <see cref="HtmlColor.ConvertOleColor"/> converts the specified OLE color
		/// to an <see cref="HtmlColor"/> containing the correct color.
		/// </summary>
		[TestMethod]
		public void TestConvertOleColor()
		{
			HtmlColor color;

			color = HtmlColor.ConvertOleColor(0);
			Assert.AreEqual("black", color.ToString());

			color = HtmlColor.ConvertOleColor(255);
			Assert.AreEqual("red", color.ToString());
		}

		#endregion // ConvertOleColor

		#region Constructors

        /// <summary>
        /// Ensures the <see cref="HtmlColor"/> constructor converts named colors to their correct
        /// names.
        /// </summary>
        [TestMethod]
        public void TestConstructorWithNamedColors()
        {
            HtmlColor color;

            color = new HtmlColor(0, 0, 0);
            Assert.AreEqual("black", color.ToString());

            color = new HtmlColor(0, 0, 128);
            Assert.AreEqual("navy", color.ToString());

            color = new HtmlColor(0, 0, 255);
            Assert.AreEqual("blue", color.ToString());

            color = new HtmlColor(0, 128, 0);
            Assert.AreEqual("green", color.ToString());

            color = new HtmlColor(0, 128, 128);
            Assert.AreEqual("teal", color.ToString());

            color = new HtmlColor(0, 255, 0);
            Assert.AreEqual("lime", color.ToString());

            color = new HtmlColor(0, 255, 255);
            Assert.AreEqual("aqua", color.ToString());

            color = new HtmlColor(128, 0, 0);
            Assert.AreEqual("maroon", color.ToString());

            color = new HtmlColor(128, 0, 128);
            Assert.AreEqual("purple", color.ToString());

            color = new HtmlColor(128, 128, 0);
            Assert.AreEqual("olive", color.ToString());

            color = new HtmlColor(128, 128, 128);
            Assert.AreEqual("gray", color.ToString());

            color = new HtmlColor(192, 192, 192);
            Assert.AreEqual("silver", color.ToString());

            color = new HtmlColor(255, 0, 0);
            Assert.AreEqual("red", color.ToString());

            color = new HtmlColor(255, 0, 255);
            Assert.AreEqual("fuchsia", color.ToString());

            color = new HtmlColor(255, 255, 0);
            Assert.AreEqual("yellow", color.ToString());

            color = new HtmlColor(255, 255, 255);
            Assert.AreEqual("white", color.ToString());
        }

        /// <summary>
        /// Ensures the <see cref="HtmlColor"/> constructor converts unnamed colors to their hex
        /// codes.
        /// </summary>
        [TestMethod]
        public void TestConstructorWithUnnamedColors()
        {
            HtmlColor color;

            color = new HtmlColor(0, 128, 255);
            Assert.AreEqual("#0080ff", color.ToString());
        }

        #endregion // Constructors

        #endregion // Methods
    }

}
